package com.studentcontrol;

import com.dao.StudentDao;
import org.apache.struts2.interceptor.RequestAware;

import javax.naming.NamingException;
import java.sql.SQLException;
import java.util.Map;

/**
 * @author :wn
 * @program : 学生信息管理系统
 * @descript :
 * @create :2020-11-13 23:13
 */

public class AddStudentAction implements RequestAware {
    private String name;
    private String age;
    private String sex;
    private String dept;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getDept() {
        return dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    public String add() throws SQLException, NamingException {


        boolean addStudent = new StudentDao().addWay(name, age, sex, dept);
        if (addStudent) {
            String addInformation = "添加成功";
            request.put("addInformation", addInformation);
            return "success";
        } else {
            String addInformation = "添加失败";
            request.put("addInformation", addInformation);
            return "error";
        }

    }

    Map<String, Object> request;

    @Override
    public void setRequest(Map<String, Object> map) {
        this.request = map;
    }
}
